package de.koller.worlders;

import de.koller.oceanFramework.OceanException;
import de.koller.oceanFramework.gl.OceanGame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class WorldersStart {

	public static final String TITLE = "200 Million v0.3";

	private static OceanGame findRes() {
		OceanGame game;
		try {
			DisplayMode[] modes = Display.getAvailableDisplayModes();
			DisplayMode cand = null;
			
			for( DisplayMode d : modes )
				if( d.getWidth() == 800 && d.getHeight() == 600 )
					if( cand == null )
						cand = d;
					else
						if( d.getBitsPerPixel() == 32 ) {
							if( d.getFrequency() >= cand.getFrequency() )
								cand = d;
						} else
							cand = d;
			
			if( cand == null )
				throw new OceanException( "DisplayMode not found" );
			
			System.out.println( "DisplayMode: " + cand.getWidth() + "x" + cand.getHeight()
					+ "x" + cand.getBitsPerPixel() + " (" + cand.getFrequency() + "Hz)" );
			game = new OceanGame( cand, TITLE, false, false, true );
		} catch( Exception ex ) {
			JOptionPane.showMessageDialog( null, "Konnte nicht 800x600 Auflösung für Ihre " +
					"Grafikkarte finden.", "DisplayMode", JOptionPane.ERROR_MESSAGE );
			game = OceanGame.create( WorldersStart.TITLE, 800, 600, 32, 60, false, false );
		}
		return game;
	}
	
	private WorldersStart() {}

	public static void main( String[] args ) {
		try {
//			UIManager.setLookAndFeel( "javax.swing.plaf.nimbus.NimbusLookAndFeel" );
//			UIManager.setLookAndFeel( "com.sun.java.swing.plaf.motif.MotifLookAndFeel" );
//			UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
			UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
		} catch( Exception e ) {
			System.out.println("Error setting native LAF: " + e);
		}
		
		OceanGame.enableClientChoose = true;
		OceanGame game;
		game = findRes();
//		game = OceanGame.create( TITLE );
		
		game.getRoot().addChild( RootFactory.sandbox() );
		game.start();

	}
	
}
